<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML >
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" > 
<html>
<head>
<base href="<%=basePath%>">

<title>文章链接</title>

<link rel="stylesheet" type="text/css" href="./js/bootstrap-3.3.5-dist/css/bootstrap.css" />
<link href="./js/metisMenu/metisMenu.min.css" rel="stylesheet">
<link href="./css/sb-admin/sb-admin-2.css" rel="stylesheet">
<link rel="stylesheet" href="./js/font-awesome/css/font-awesome.min.css">
<link href="./css/base.css" rel="stylesheet">
<link rel="stylesheet" href="./js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="./js/bootstrap-multiselect/bootstrap-multiselect.css"/>
<link rel="stylesheet" href="./js/bootstrap-3.3.5-dist/css/bootstrap-datetimepicker.css">
<link rel="stylesheet" href="./css/illness.css">
<script type="text/javascript" src="./js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="./js/bootstrap-3.3.5-dist/js/bootstrap.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-all.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="./js/metisMenu/metisMenu.js"></script>
<script src="./js/bootstrap-multiselect/bootstrap-multiselect.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="./js/bootstrap-jquery-plugin/jquery.bootstrap.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript" src="./js/xss.js"></script>
</head>
<body>
	<jsp:include page="../template/head.jsp" />
	<jsp:include page="../template/leftnav.jsp" />
	<div id="page-wrapper">
	<div>
		<h1>文章链接列表</h1>
	</div>
	<div class="content">
		<form class="form-inline">
			<div class="form-group">
				<label for="title">标题：</label>
				<input type="text" id="title" class="form-control" placeholder="请输入标题" onkeyup="filters(this)" onchange="filters(this)">
			</div>
			<div class="form-group">
				<label for="source">来源公众号：</label>
				<input type="text" id="source" class="form-control" placeholder="请输入来源公众号" onkeyup="filters(this)" onchange="filters(this)">
			</div>
			<div class="form-group">
				<label for="time">创建时间：</label>
				<input class="form-control" type="text" id="startTime" placeholder="请输入开始的时间">
				<span>到</span>
				<input class="form-control" type="text" id="endTime" placeholder="请输入结束的时间">
				<button class="btn  search-btn" id="search">搜索</button>
				<button id="create" class="btn">新增</button>
				<button id="reset" class="btn btn-default">重置</button>
			</div>
		</form>
			 <table id="table" data-toolbar="#toolbar" data-toggle="table" data-row-style="rowStyle" data-classes="table  table-no-bordered"
		           data-minimum-count-columns="2"  data-cache="false" data-pagination="true"  data-striped="data-striped"
		           data-page-list="[5, 10, 20, 50]"  data-query-params="tableQueryParams" style="word-break:break-all;"
		           data-side-pagination="server" data-page-size=10 data-url="./linkAricle/getLinkAricleList">
		           <thead>
					<tr class="headTr">
						<th data-field="title" data-width="13%" >标题</th>
						<th data-field="linkAricle" data-width ="27%" >文章链接</th>
						<th data-field="organization" data-width ="10%">所属机构</th>
						<th data-field="source" data-width ="10%">来源公众号</th>
						<th data-field="creator" data-width ="10%">创建人</th>
						<th data-field="startTime" data-width ="10%" data-formatter="dateFormatter">创建日期</th>
						<th data-field="operation" data-width ="10%" data-formatter="operFormatter">操作</th>
					</tr>
				</thead>
	    	</table>
			
	    <div id="illOperTemp" style="display:none">
			<ul class="list-inline">
				<li role="presentation"><a role="button" class="btn btn-danger" style="margin-top:5px;">删除</a></li>
			</ul>
		</div>
    </div>
</div>
<script type="text/javascript">
$(function () {	
	"use strict";
	
	$('#search').on('click', function (e) {
		e.preventDefault();
		searchOrder();
	});
	
	$('#create').on('click', function (e) {
		e.preventDefault();
		window.location.href="./jsp/aricle/linkAricleEdit.jsp";
	});
	
});

function tableQueryParams(params) {
	var queryObj = getQueryObject();
	var newParams = $.extend(params,queryObj);
	return newParams;
}
	
function getQueryObject(){
	var queryObj;
	var title = $("#title").val();
	var source = $("#source").val();
	var startVal = $("#startTime").val();
	var endVal = $("#endTime").val();
	
	//设置默认时间为1900-01-01
	var defaultTime = new Date();
	defaultTime.setFullYear(1900,0,1);
	defaultTime.setHours(0);
	defaultTime.setMinutes(0);
	defaultTime.setSeconds(0);
	//日期
	var startTime = new Date(startVal);
	var endTime = new Date(endVal);
	startTime.setHours(0);
	startTime.setMinutes(0);
	startTime.setSeconds(0);
	endTime.setHours(23);
	endTime.setMinutes(59);
	endTime.setSeconds(59);
	
	var todayStart = new Date();
	var todayEnd = new Date();
	todayStart.setHours(0);
	todayStart.setMinutes(0);
	todayStart.setSeconds(0);
	todayEnd.setHours(23);
	todayEnd.setMinutes(59);
	todayEnd.setSeconds(59);
	
	if(startVal == "" || endVal == ""){
		var queryObj = {
			isSearch: true,
			title: title,
			source: source,
			startTime : defaultTime,
			endTime : todayEnd
		}
	}else{
		var queryObj = {
			isSearch: true,
			title: title,
			source: source,
			startTime : startTime,
			endTime : endTime
		}
	}
	
	if(title ==""){
		delete queryObj.title;
	}
	
	if(source ==""){
		delete queryObj.source;
	}
	
	return queryObj;
}
	
function searchOrder(){
	var queryObj = getQueryObject();
	$('#table').bootstrapTable('refresh', {
		query : {
			offset: 0
		},
	});
}

function dateFormatter(value, row){
	if(value!=null){
		return getSmpFormatDateByLong(value, true);
	}else{
		return '-';
	}
}

function operFormatter(value, row) {
	var operTemp = $("#illOperTemp").clone();
	var lis = operTemp.find("ul li");
	lis.eq(0).find("a").attr("onClick", "deleteLinkAricle(\""+row.id+"\")");	
	return operTemp.html();
}

function deleteLinkAricle(id){
	$.messager.model = { 
		//定义消息提示框
	   	ok:{ text: "确定", classed: 'btn-success' },
	    cancel:{text:"取消",classed: 'btn-danger' }
	};
	$.messager.confirm("确认操作", "确定删除本文?", function() {
		$.ajax({
			url : "./linkAricle/deleteLinkAricle",
			type : 'POST',
			data : {
				id :id
			},
			dataType : 'json',
			success : function(ret) {
                 if(ret.resultCode == 0){
                     $.messager.popup("操作成功");
                     $('#table').bootstrapTable('refresh', {
						query : {
							offset: 0
						},
						silent : true
					});
                 }else{
                     $.messager.popup("操作失败");
                 }
			}
		});
	});
}
</script>
</body>
</html>
